package com.ruoyi.teaching.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.teaching.domain.vo.BatchHoliday;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.teaching.domain.HolidayConfig;
import com.ruoyi.teaching.service.IHolidayConfigService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 节假日配置Controller
 *
 * @author sunshine
 * @date 2024-01-19
 */
@RestController
@RequestMapping("/holiday_config")
public class HolidayConfigController extends BaseController
{
    @Autowired
    private IHolidayConfigService holidayConfigService;

    /**
     * 查询节假日配置列表
     */
    @RequiresPermissions("teaching:holiday_config:list")
    @GetMapping("/list")
    public TableDataInfo list(HolidayConfig holidayConfig)
    {
        startPage();
        List<HolidayConfig> list = holidayConfigService.selectHolidayConfigList(holidayConfig);
        return getDataTable(list);
    }

    /**
     * 导出节假日配置列表
     */
    @RequiresPermissions("teaching:holiday_config:export")
    @Log(title = "节假日配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HolidayConfig holidayConfig)
    {
        List<HolidayConfig> list = holidayConfigService.selectHolidayConfigList(holidayConfig);
        ExcelUtil<HolidayConfig> util = new ExcelUtil<HolidayConfig>(HolidayConfig.class);
        util.exportExcel(response, list, "节假日配置数据");
    }

    /**
     * 获取节假日配置详细信息
     */
    @RequiresPermissions("teaching:holiday_config:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(holidayConfigService.selectHolidayConfigById(id));
    }

    /**
     * 新增节假日配置
     */
    @RequiresPermissions("teaching:holiday_config:add")
    @Log(title = "节假日配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody List<BatchHoliday> holidayConfig)
    {
        return toAjax(holidayConfigService.insertHolidayConfig(holidayConfig));
    }

    /**
     * 修改节假日配置
     */
    @RequiresPermissions("teaching:holiday_config:edit")
    @Log(title = "节假日配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody List<BatchHoliday> holidayConfig, @RequestParam Long id)
    {
        return toAjax(holidayConfigService.updateHolidayConfig(holidayConfig,id));
    }

    /**
     * 删除节假日配置
     */
    @RequiresPermissions("teaching:holiday_config:remove")
    @Log(title = "节假日配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(holidayConfigService.deleteHolidayConfigByIds(ids));
    }
}
